<script setup>
import {
	onLoad
} from '@dcloudio/uni-app'
import {
	ref
} from 'vue';
import { uniFetch } from '../../api/uni-fetch';

import {
	useUserStore
} from "../../store/user"

// import {} from "/uni_modules/ws-wx-privacy/components/ws-wx-privacy/util.js"

// function chooseAvatar(e) {
// 	console.log(e);
// 	uni.getPrivacySetting({
// 		sucess: (res) => {
// 			console.log(res);
// 		}
// 	})
// }

onLoad(() => {
	wx.getPrivacySetting({
		success: res => {
			console.log(res)
			if (res.needAuthorization) {
				// 需要弹出隐私协议

			} else {
				// 用户已经同意过隐私协议，所以不需要再弹出隐私协议，也能调用隐私接口
			}
		},
		fail: (err) => {
			console.log(err.msg, '隐私协议接口出错');
		},
	})
})

const props = defineProps(['page'])

const pageBack = ref('')
pageBack.value = props.page

console.log(props, 'pageBack.value ');


// 手机号
const getPhone = async (event) => {

	const res = await uniFetch.post('/user/phone', event.detail)
	console.log(res);
	if (res.data.user) {
		uni.showToast({
			icon: 'none',
			title: '绑定成功',
			duration: 1000
		})

		const store = useUserStore()

		uni.setStorageSync('userLoginCode', res.data)

		store.token = res.data.token
		store.userInfo = res.data.user

		console.log(pageBack.value, 'pageBack.value');

		setTimeout(() => {
			if (pageBack.value === 'mine') {
				return uni.switchTab({
					url: '/pages/mine/mine'
				})
			}
			if (pageBack.value ==='memberEquity') {
				return uni.redirectTo({
					url: '/subpkg/MemberEquity/MemberEquity'
				})
			}
		}, 1000);
	}
}
</script>


<template>
	<view class="user-login">





		<view class="box">
			<view class="wai" hover-stop-propagation="false">
				<view class="nei" hover-stop-propagation="false">
					<image class="image" src="/static/logo1.png" mode="aspectFit" lazy-load>
					</image>

				</view>
			</view>

			<view class="title">
				手机号授权
			</view>
			<view class="tips">
				为获得更好的用户体验,便于售后服务,我们需要您授权您的手机号,此数据加密保存,不会暴露给第三方机构
			</view>
			<button open-type="getPhoneNumber" @getphonenumber="getPhone">授权手机号</button>
		</view>


		<ws-wx-privacy id="privacy-popup"></ws-wx-privacy>

	</view>
</template>


<style lang="scss" scoped>
.user-login {
	display: flex;
	justify-content: center;
	padding: 220rpx 0;
	height: 100vh;
	background: generate-gradient-bottom(#3bae43, #eaf0eb);

	.box {
		position: relative;
		background-color: #f3fef3;
		width: 80%;
		height: 660rpx;
		border-radius: 15rpx;

		.wai {
			position: absolute;
			top: -80rpx;
			left: 50%;
			transform: translateX(-50%);
			display: flex;
			justify-content: center;
			align-items: center;
			width: 160rpx;
			height: 160rpx;
			border-radius: 50%;
			background-color: $custom-theme-color;
			box-shadow: 0px 0px 5px #bc78db;

			.nei {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 150rpx;
				height: 150rpx;
				border-radius: 50%;
				background-color: #fefefe;

				image {
					width: 95%;
					height: 95%;
					border-radius: 50%;
				}
			}
		}

		.title {
			padding-top: 100rpx;
			font-size: 37rpx;
			color: #0c010b;
			text-align: center;
			letter-spacing: 15rpx;
		}

		.tips {
			padding: 80rpx 0;
			margin: 0 auto;
			width: 85%;
			font-size: 28rpx;
			color: #110210;
			line-height: 1.5;
		}

		button {
			position: absolute;
			bottom: 120rpx;
			left: 50%;
			transform: translateX(-50%);
			color: #fefefe;
			background-color: #f73000;
			width: 400rpx;
			text-align: center;
		}
	}
}
</style>